package com.beagle.njddapp.base;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import butterknife.ButterKnife;

/**
 * 基础封装的BaseMvpActivity
 * @param <V>
 * @param <P>
 */
public abstract class BaseMvpActivity <V extends BaseView, P extends BasePresenter> extends AppCompatActivity implements BaseMvp< V, P> {
    protected P presenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        //创建Presenter
        presenter = createPresenter();
        if (presenter != null) {
            //将Model层注册到Presenter中
          //  presenter.registerModel(createModel());
            //将View层注册到Presenter中
            presenter.registerView(getMvpView());
        }
        init();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (presenter != null) {
            //Activity销毁时的调用，让具体实现BasePresenter中onViewDestroy()方法做出决定
            presenter.destroy();
        }

    }
    public abstract int getLayoutId();

    public abstract void init();


}
